package evolutionaryProblems;

public abstract class RunPhenotype implements Runnable{
	
//	protected T runPhenotype;
	protected RunningStatus status; 
	
	
	@Override
	public void run() {
		status = RunningStatus.RUNNING; 
		while (status == RunningStatus.RUNNING) {
			doTimeStep(); 
		}
		status = RunningStatus.FINISHED; 
	}
	
	protected abstract void doTimeStep();

	public double[] convertDtod(Double[] list){
		double[] convert = new double[list.length]; 
		for (int i = 0; i < convert.length; i++) {
			convert[i] = list[i]; 
		}
		return convert; 
	}
	
	public void kill(){
		if (status == RunningStatus.FINISHED){
			return; 
		}
		status = RunningStatus.TERMINATING; 
	}
	
	public boolean haveKilled(){
		return status == RunningStatus.FINISHED; 
	}

	public void pause(boolean pause) {
		if (pause) {
			status = RunningStatus.PAUSED; 
		} else {
			new Thread(this).start();  
		}
	}

}
